//
//  ViewController.m
//  MD5
//
//  Created by YiXuePxh on 15/6/23.
//  Copyright (c) 2015年 上海益学. All rights reserved.
//

#import "ViewController.h"
#import <CommonCrypto/CommonDigest.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString* md5 = @"appId180666clientType2courseIdsD228F74E1A85DABC66AA44357CDD5124";
    NSString* sign = [self md5:md5];
    NSLog(@"sign:%@",sign.uppercaseString);
}
//md5 加密
-(NSString*) md5:(NSString*) str
{
    const char *cStr = [str UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, strlen(cStr), result );
    
    NSMutableString *hash = [NSMutableString string];
    for(int i=0;i<CC_MD5_DIGEST_LENGTH;i++)
    {
        [hash appendFormat:@"%02X",result[i]];
    }
    return [hash lowercaseString];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
